<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <div th:fragment="top1" class="header">
        <div class="welcome fl">欢迎来到天天生鲜!</div>
        <div class="fr">
            <div class="login_info fl">
                欢迎您：<em>张 山</em>
            </div>
            <div class="login_btn fl">
                <th:block th:if="${session.user!=null}">
                    <a href="javascript:void(0)" th:text="${session.user.name}"></a>
                    <a href="javascript:void(0)" onclick="logout()">退出</a>
                </th:block>
                <th:block th:if="${session.user==null}">
                    <th:block th:if="${returnUri == null}">
                        <a th:href="|/page/login?returnUri=/|">登录</a>
                    </th:block>
                    <th:block th:if="${returnUri != null}">
                        <a th:href="|/page/login?returnUri=${returnUri}|">登录</a>
                    </th:block>
                    <span>|</span>
                    <a href="/page/register">注册</a>
                </th:block>

            </div>
            <div class="user_link fl">
                <span>|</span>
                <a href="/page/userInfo">用户中心</a>
                <span>|</span>
                <a href="/page/cart/list">我的购物车</a>
                <span>|</span>
                <a href="/page/userOrder">我的订单</a>
            </div>
        </div>

        <script>
            function logout() {
                $.post(
                    '/user/logout',
                    function (result) {
                        if (result.code == 0){
                            var returnUri = '[[${returnUri}]]';
                            if (returnUri == ''){
                                returnUri = '/';
                            }
                            mylayer.okUrl(result.msg,'/page/login?returnUri=' + returnUri);
                        }
                    },
                    'json'
                );
            }
        </script>

    </div>



</body>
</html>